package cn.itsource.controller;

import cn.itsource.bean.Product;
import cn.itsource.dto.ProductDto;
import cn.itsource.query.ProductQuery;
import cn.itsource.service.IProductService;
import cn.itsource.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : 张金铭
 * @description :
 * @create :2022-11-29 09:44:00
 */
@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private IProductService productService;

    @PostMapping("/pagelist")
    public JsonResult getPage(@RequestBody ProductQuery query){


        return productService.getPage(query);
    }


    @PostMapping("/up/{state}")
    public JsonResult upState(@RequestBody ProductQuery query, @PathVariable("state") Long state){


        return productService.upState(query,state);
    }

    @PostMapping("/save")
    public JsonResult saveOrUp(@RequestBody Product product){

        return productService.add(product);
    }

    @GetMapping("/{id}")
    public JsonResult getById(@PathVariable("id") Long id){

        return productService.getPetById(id);
    }

    @PostMapping("/delete")
    public JsonResult deleteByIds(@RequestBody ProductQuery query){

        return productService.deleteByIds(query);
    }


    @PostMapping("/submitOrder")
    public JsonResult submitOrder(@RequestBody ProductDto productDto)  {
        return JsonResult.success(productService.submitOrder(productDto));
    }
}
